package com.googlecode.agileplugins.cruisewatcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MasterFeedParser implements FeedParser {
    public LatestBuildState parseLatestBuildResult(String rssfeed) {
        FeedParser[] parsers = {
                new CruiseControlFeedParser(),
                new HudsonFeedParser()
        };
        List errors = new ArrayList();
        for (FeedParser parser : parsers) {
            try {
                return parser.parseLatestBuildResult(rssfeed);
            } catch (Exception e) {
                errors.add(e.getMessage());
            }
        }
        throw new RuntimeException("Could not parse RSS feed using: " + Arrays.asList(parsers) +
                "\n\nErrors: " + errors.toString());
    }
}
